package com.hualan.sfzy.controller.consult;

import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.model.entity.ConsultOrder;
import com.hualan.sfzy.model.vo.ConsultOrderVO;
import com.hualan.sfzy.service.impl.consult.ConsultOrderServiceImpl;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/consultOrder")
// 咨询师订单控制      注意没有修改

public class ConsultOrderController {
    @Autowired
    private ConsultOrderServiceImpl service;
    @PostMapping
    public Result add(@RequestBody ConsultOrder entity){
        return service.add(entity) > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Integer id){
        return service.remove(id) > 0 ? Result.success() : Result.error();
    }
    @DeleteMapping
    public Result removeBatch(Integer[] ids){
        return service.removeBatch(ids) > 0 ? Result.success() : Result.error();
    }

    // 动态分页查询
    @GetMapping("/page")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM ,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam (value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           ConsultOrderVO entity){
        return Result.success(service.selectPro(pageNum,pageSize,entity));
    }
    // 查询所有
    @GetMapping
    public Result find(){
        return Result.success(service.selectAll());
    }
    // 通过用户id查询
    @GetMapping("page/userId/{id}")
    public Result findByUserId(@RequestParam(value = CommonConstant.PAGE_NUM ,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam (value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           @PathVariable Integer id){
        return Result.success(service.selectByUserId(pageNum,pageSize,id));
    }
    @GetMapping("page/userIdPro/{id}")
    public Result findByUserIdPro(@RequestParam(value = CommonConstant.PAGE_NUM ,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                               @RequestParam (value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                               @PathVariable Integer id){
        return Result.success(service.selectByUserIdPro(pageNum,pageSize,id));
    }



    // 通过咨询师id查询
    @GetMapping("page/consultId/{id}")
    public Result findByConsultId(@RequestParam(value = CommonConstant.PAGE_NUM ,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam (value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           @PathVariable Integer id){
        return Result.success(service.selectByConsultId(pageNum,pageSize,id));
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        return Result.success(service.findById(id));
    }



}
